package yu.liu.personal.app.myapplication.components;

import android.content.Context;
import android.graphics.Color;
import android.graphics.drawable.ColorDrawable;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.PopupWindow;

import yu.liu.personal.app.myapplication.utils.ResourceManager;

/**
 * Created by yu.liu on 2016/9/28.
 */

public abstract class PopupCollection extends PopupWindow {

    protected Context resContext;
    protected ResourceManager resManager;
    protected View anchorView;
    protected View windowView;

    protected OnConfirmClickListener onConfirmClickListener;
    protected OnCancelClickListener onCancelClickListener;

    public PopupCollection(Context context) {
        super(context);
        resContext = context;
        resManager = ResourceManager.getManager(resContext);
    }

    public void initWindow(View anchor, View window) {
        anchorView = anchor;
        windowView = window;
        loadViews();
        loadMembers();
        postSetup();
    }

    public void initWindow(View anchor, int window) {
        anchorView = anchor;
        windowView = LayoutInflater.from(resContext).inflate(window, null);
        setBackgroundDrawable(new ColorDrawable(Color.parseColor("#55000000")));
        loadViews();
        loadMembers();
        postSetup();
    }

    public void setOnConfirmClickListener(
            OnConfirmClickListener onConfirmClickListener) {
        this.onConfirmClickListener = onConfirmClickListener;
    }

    public void setOnCancelClickListener(
            OnCancelClickListener onCancelClickListener) {
        this.onCancelClickListener = onCancelClickListener;
    }

    public abstract boolean showPopupWindow();

    public abstract void loadViews();

    public abstract void loadMembers();

    public abstract void postSetup();

    public abstract void updateViews();

    public interface OnConfirmClickListener {
        void onConfirm();
    }

    public interface OnCancelClickListener {
        void onCancel();
    }

}
